package com.chenqq.qsocket.handler;

import android.util.Log;

import com.chenqq.qsocket.listener.SocketMessageListener;
import com.chenqq.qsocket.message.AcceptReceiveFileMessage;
import com.chenqq.qsocket.message.FileTask;
import com.chenqq.qsocket.message.SocketMessage;
import com.chenqq.qsocket.tools.LogShow;

import java.io.File;
import java.io.IOException;

import org.apache.mina.core.session.IoSession;
import org.json.JSONException;


public class AcceptReceiveFileMessageHandler extends FileMessageHandler {

	@Override
	public void handleMessage(SocketMessage msg, IoSession session) throws JSONException {
		AcceptReceiveFileMessage requestSendFileMessage = new AcceptReceiveFileMessage(
				msg);
		long id = requestSendFileMessage.getId();
		FileTask fileTask = mFileTasks.get(id);
		if (fileTask == null) {
			LogShow.showV("wrong file task id " + id);
			session.closeOnFlush();
		} else {
			LogShow.showV("接收到数据"+fileTask.zippedFilePath);
			sendFilePart(fileTask, session);
		}
	}

}
